#!/bin/bash
#SERVERS=("192.168.1.10" "192.168.1.11" "192.168.1.12")
#RESULT_FILE="/tmp/ping_result.txt"
#> $RESULT_FILE  # 清空结果文件
#for server in "${SERVERS[@]}"; do
#    if ping -c 2 -W 3 $server &> /dev/null; then
#        echo "$server 存活" >> $RESULT_FILE
#    else
#        echo "$server 不可达" >> $RESULT_FILE
#    fi
#done
#echo "检测完成，结果见 $RESULT_FILE"
result_file="/tmp/ping_result1.txt"
>$result_file
ips="$(cat ip.txt)"
for ip in $ips;do
	if ping -c 3 -W 3 $ip>/dev/null;
		then echo "$ip 存活">>$result_file
		else echo "$ip 不通">>$result_file	
	fi
done
echo "结果见 $result_file"

